using System;
using System.Text;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class Admin_EditSiteContent : System.Web.UI.Page
{
    string strCurrentType = string.Empty;

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {

            StringBuilder sbuScript = new StringBuilder();

            sbuScript.AppendLine("function ddlCheck()");
            sbuScript.AppendLine("{");
            sbuScript.AppendLine("if (document.forms[0]."+ddlTypes.ClientID+".selectedIndex == 0)");
            sbuScript.AppendLine("{");           
            sbuScript.AppendLine("alert('You need to select a Type to edit'); return false;");
            sbuScript.AppendLine("}");
            sbuScript.AppendLine("}");

            butSave.OnClientClick = "return ddlCheck();";
            butTopSave.OnClientClick = "return ddlCheck();";


            ClientScript.RegisterClientScriptBlock(this.GetType(), "script", sbuScript.ToString(),true);


            ddlTypes.DataSource = ContentManager.GetSiteContentTypes();
            ddlTypes.DataTextField = "Text";
            ddlTypes.DataValueField = "Value";
            ddlTypes.DataBind();
            ddlTypes.Items.Insert(0,new ListItem(""));
            ddlTypes.SelectedIndex = 0;

            if (Request.QueryString["Type"] != null && Request.QueryString["Type"] != "")
            {
                strCurrentType = Request.QueryString["Type"];
                LoadData();
               
                ddlTypes.ClearSelection();
                ddlTypes.Items.FindByValue(strCurrentType).Selected = true;
            }            
        }
    }

    protected void LoadData()
    {
        
        ftb_Resume.Text = ContentManager.GetSiteData(Convert.ToInt32(strCurrentType));
        ftb_Resume.ReadOnly = false;
        butTopSave.Enabled = true;
        butSave.Enabled = true;

    }

    protected void but_Save_Click(object sender, EventArgs e)
    {
        if (ddlTypes.SelectedIndex > 0)
        {

           // ContentManager.UpdateSiteData(ftb_Resume.Text, ContentManager.SiteContentType.AboutMe);
            ContentManager.UpdateSiteData(ftb_Resume.Text, Convert.ToInt32(ddlTypes.SelectedValue));
        }
        
    }
    protected void ddlTypes_SelectedIndexChanged(object sender, EventArgs e)
    {

        strCurrentType = ddlTypes.SelectedValue;
        if (!(strCurrentType.Equals("")))
        {
            LoadData();
        }
        else
        {
            ftb_Resume.Text = "";
            ftb_Resume.ReadOnly = true;
            butTopSave.Enabled = false;
            butSave.Enabled = false;
        }

    }
}
